#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

from dotenv import load_dotenv

load_dotenv(verbose=True)

from utils.file_util import dirs_mk_static_list, dirs_mk, mk_empty_python


def mk_migrations(app_list: list):
    for app in app_list:
        dirs_mk(f'migrations/{app}')
        mk_empty_python(f'migrations/{app}/__init__.py')


def make_need_statics_folders():
    """ 构建静态文件夹
    :return:
    """
    static_name_list = ['admin', 'django_extensions', 'import_export', 'rest_framework']
    dirs_mk_static_list(static_name_list)
    dirs_mk("logs")
    app_str = os.environ.get('APP_LIST')
    app_list = app_str.split(',')
    print(f"app_list:{app_list}")
    mk_migrations(app_list)  # add apps


def main():
    """Run administrative tasks."""
    make_need_statics_folders()
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'base.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()
